import store from "@/store";

export default (to, from, next) => {
  if (store.getters.userInfo) {
    if (to.path === '/home') {
      next();
    } else {
      let [allowPath, isAdmin] = store.getters.userInfo.roles.reduce((group, role) => {
        group[0] += role.menuUrls;
        group[1] = group[1] || !!role.isAdmin;
        return group;
      }, ['', false]);
      isAdmin ? next() : allowPath.includes(to.path) ? next() : next('/login');
    }
  } else {
    next('/login');
  }
}
